<?php include('../variables/variables.php'); ?>

<?php

if(!session_id()) session_start(); 
$con = mysql_connect($dbserver, $dbuser, $dbpass);
if ($con)
{
	mysql_select_db($db, $con);

	if ($_POST['name'] && $_POST['email'] && $_POST['password'] && $_POST['phone_number'] && $_POST['city'] && $_POST['street'] && $_POST['province'] && $_POST['postal_code'] && $_POST['birth_date'] && $_POST['membership'])
	{
		$q = fquery($add_patron, array($_POST['name'], $_POST['email'], $_POST['password'], $_POST['phone_number'], $_POST['city'], $_POST['street'], $_POST['province'], $_POST['postal_code'], $_POST['birth_date'], '0', $_SESSION['id'], $_POST['membership']));
		$result = mysql_query($q);
		mysql_close($con);
		if ($result)
		{
			header("location: /admin.php?msg=New patron added successfully");
		}
		else
		{
			header("location: /add_patron.php?err=Failed to add the new user to the system");
		}
	}
	else
	{
		mysql_close($con);
		header("location: /add_patron.php?err=Please fill in all fields");
	}
}

?>
